package com.ltkj.shop.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ltkj.shop.domain.vo.ShopRestaurantVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ltkj.common.log.annotation.Log;
import com.ltkj.common.log.enums.BusinessType;
import com.ltkj.common.security.annotation.RequiresPermissions;
import com.ltkj.shop.domain.ShopRestaurant;
import com.ltkj.shop.service.IShopRestaurantService;
import com.ltkj.common.core.web.controller.BaseController;
import com.ltkj.common.core.web.domain.AjaxResult;
import com.ltkj.common.core.utils.poi.ExcelUtil;
import com.ltkj.common.core.web.page.TableDataInfo;

/**
 * 餐饮商户Controller
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Api(tags = "餐饮商户")
@RestController
@RequestMapping("/restaurant")
public class ShopRestaurantController extends BaseController
{
    @Autowired
    private IShopRestaurantService shopRestaurantService;

    /**
     * 查询餐饮商户列表
     */
    @ApiOperation("查询餐饮商户列表")
    @RequiresPermissions("shop:restaurant:list")
    @GetMapping("/list")
    public TableDataInfo list(ShopRestaurant shopRestaurant)
    {
        startPage();
        List<ShopRestaurantVo> list = shopRestaurantService.selectShopRestaurantList(shopRestaurant);
        return getDataTable(list);
    }

    /**
     * 导出餐饮商户列表
     */
    @ApiOperation("导出餐饮商户列表")
    @RequiresPermissions("shop:restaurant:export")
    @Log(title = "餐饮商户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopRestaurant shopRestaurant)
    {
        List<ShopRestaurantVo> list = shopRestaurantService.selectShopRestaurantList(shopRestaurant);
        ExcelUtil<ShopRestaurantVo> util = new ExcelUtil<ShopRestaurantVo>(ShopRestaurantVo.class);
        util.exportExcel(response, list, "餐饮商户数据");
    }

    /**
     * 获取餐饮商户详细信息
     */
    @ApiOperation("获取餐饮商户详细信息")
    @RequiresPermissions("shop:restaurant:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopRestaurantService.selectShopRestaurantById(id));
    }

    /**
     * 新增餐饮商户
     */
    @ApiOperation("新增餐饮商户")
    @RequiresPermissions("shop:restaurant:add")
    @Log(title = "餐饮商户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopRestaurant shopRestaurant)
    {
        return shopRestaurantService.insertShopRestaurant(shopRestaurant);
    }

    /**
     * 修改餐饮商户
     */
    @ApiOperation("修改餐饮商户")
    @RequiresPermissions("shop:restaurant:edit")
    @Log(title = "餐饮商户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopRestaurant shopRestaurant)
    {
        return toAjax(shopRestaurantService.updateShopRestaurant(shopRestaurant));
    }

    /**
     * 删除餐饮商户
     */
    @ApiOperation("删除餐饮商户")
    @RequiresPermissions("shop:restaurant:remove")
    @Log(title = "餐饮商户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopRestaurantService.deleteShopRestaurantByIds(ids));
    }
}
